home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / plugin-editor.php < prev    next >
Encoding:
PHP Script  |  2005-02-25  |  3.1 KB  |  125 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __("Edit Plugins");
  5. $parent_file = 'plugins.php';
  6.  
  7. $wpvarstoreset = array('action','redirect','profile','error','warning','a','file');
  8. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  9.     $wpvar = $wpvarstoreset[$i];
  10.     if (!isset($$wpvar)) {
  11.         if (empty($_POST["$wpvar"])) {
  12.             if (empty($_GET["$wpvar"])) {
  13.                 $$wpvar = '';
  14.             } else {
  15.                 $$wpvar = $_GET["$wpvar"];
  16.             }
  17.         } else {
  18.             $$wpvar = $_POST["$wpvar"];
  19.         }
  20.     }
  21. }
  22.  
  23. $plugins = get_plugins();
  24. $plugin_files = array_keys($plugins);
  25.  
  26. if (empty($file)) {
  27.     $file = $plugin_files[0];
  28. }
  29.  
  30. $file = validate_file_to_edit($file, $plugin_files);
  31. $real_file = get_real_file_to_edit("wp-content/plugins/$file");
  32.  
  33. switch($action) {
  34.  
  35. case 'update':
  36.  
  37.     if ($user_level < 5) {
  38.         die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>'));
  39.     }
  40.  
  41.     $newcontent = stripslashes($_POST['newcontent']);
  42.     if (is_writeable($real_file)) {
  43.         $f = fopen($real_file, 'w+');
  44.         fwrite($f, $newcontent);
  45.         fclose($f);
  46.         header("Location: plugin-editor.php?file=$file&a=te");
  47.     } else {
  48.         header("Location: plugin-editor.php?file=$file");
  49.     }
  50.  
  51.     exit();
  52.  
  53. break;
  54.  
  55. default:
  56.     
  57.     require_once('admin-header.php');
  58.     if ($user_level <= 5) {
  59.         die(__('<p>You have do not have sufficient permissions to edit plugins for this blog.</p>'));
  60.     }
  61.  
  62.     update_recently_edited("wp-content/plugins/$file");
  63.     
  64.     if (!is_file($real_file))
  65.         $error = 1;
  66.     
  67.     if (!$error) {
  68.         $f = fopen($real_file, 'r');
  69.         $content = fread($f, filesize($real_file));
  70.         $content = htmlspecialchars($content);
  71.     }
  72.  
  73.     ?>
  74. <?php if (isset($_GET['a'])) : ?>
  75.  <div class="updated"><p><?php _e('File edited successfully.') ?></p></div>
  76. <?php endif; ?>
  77.  <div class="wrap"> 
  78.   <?php
  79.     if (is_writeable($real_file)) {
  80.         echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>';
  81.     } else {
  82.         echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>';
  83.     }
  84.     ?>
  85.     <div id="templateside">
  86. <h3><?php _e('Plugin files') ?></h3>
  87.  
  88. <?php
  89. if ($plugin_files) :
  90. ?>
  91.   <ul>
  92. <?php foreach($plugin_files as $plugin_file) : ?>
  93.          <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
  94. <?php endforeach; ?>
  95.   </ul>
  96. <?php endif; ?>
  97. </div>
  98.     <?php    if (!$error) { ?> 
  99.   <form name="template" id="template" action="plugin-editor.php" method="post">
  100.          <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
  101.      <input type="hidden" name="action" value="update" /> 
  102.      <input type="hidden" name="file" value="<?php echo $file ?>" /> 
  103.         </div>
  104. <?php if ( is_writeable($real_file) ) : ?>
  105.      <p class="submit">
  106. <?php
  107.     echo "<input type='submit' name='submit' value='    " . __('Update File') . " »' tabindex='2' />";
  108. ?>
  109. </p>
  110. <?php else : ?>
  111. <p><em><?php _e('If this file was writable you could edit it.'); ?></em></p>
  112. <?php endif; ?>
  113.    </form> 
  114.   <?php
  115.     } else {
  116.         echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
  117.     }
  118.     ?> 
  119. </div> 
  120. <?php
  121. break;
  122. }
  123.  
  124. include("admin-footer.php") ?> 
  125.